<%@ Language=VBScript%>
<%
	Session("FormName")="F36"
%>
<!--#include file=..\checkSession.inc-->
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<!--#include file=..\jvGrid.inc-->
<%	
	Set ClsFun=server.CreateObject("Vinalines.ClsFunction")
	mode=Request("mode")
	bComm=Request("bComm")
	chon=request("chon")
'	Response.Write(chon)
	if bComm="detail" then		
		bMa=trim(Request("bMa"))
		bMaWorkFlow=Request("bMaWorkFlow")
		bMacu=Request("bMacu")
		sSQL="Select * from TvWorkFlow where MaWorkFlow ="& bMaWorkFlow 
		Set RecDL=server.CreateObject("ADODB.Recordset")
		RecDL.CursorType=3
		RecDL.CacheSize=5
		RecDL.Open sSQL,Conn
		if RecDL.RecordCount then		
			bMaWorkFlow=RecDL("MaWorkFlow")
			bTencu=trim(RecDL("TenTvWorkFlow"))
			bTen=trim(RecDL("TenTvWorkFlow"))
			Loaitim=Request("Loaitim")
			bsearch=Request("bsearch")
		end if
		RecDL.Close
		set RecDL=nothing
	else
		bMa=Request("bMa")
		bMaWorkFlow=Request("bMaWorkFlow")
		bMacu=Request("bMacu")
		bTencu=Request("bTencu")
		bTen=Request("bTen")
		Loaitim=request("Loaitim")
		bsearch=request("bsearch")
	end if
	Dim bTempComm
	Dim bMsg
	Dim Msg	
	if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)="1" or Session("IsAdmin") then
		Select Case bComm
			Case "add"
				if not KTMa(bMa,bComm) then
							sSQL="Select * from TvWorkFlow order by Id"
							Set RecMa=server.CreateObject("ADODB.recordset")
							RecMa.CursorType=3
							RecMa.CacheSize=5
							RecMa.Open sSQL,Conn	
							if RecMa.RecordCount then
								recMa.MoveLast
							    select Case RecMa("Id")
								case 9
								    Id=RecMa("Id")+1
								case 999
								    Id=RecMa("Id")+1
								case 9999
								    Id=RecMa("Id")+1
								case 99999
								    Id=RecMa("Id")+1
								case else
								    Id=RecMa("Id")
								end select
								Id=Id+1
								select case len(cstr(Id))
									case 1
										ma="0000" & cstr(Id)
									case 2
										ma="000" & cstr(Id)
									Case 3
										ma="00" & cstr(Id)
									Case 4
										ma="0" & cstr(Id)
									case 5
										ma=cstr(Id)
								end select
							else
								Id=1
								ma="00001"
							end if		
							RecMa.Close
							Set RecMa=nothing
						sSQL="Insert into TvWorkFlow(Id,MaTvWorkFlow,TenTvWorkFlow,MaWorkFlow,Dangky)values('"& Id &"','"& trim(ClsFun.ModiString(bMa)) &"','"& trim(ClsFun.ModiString(bTen)) &"','"& ma &"','"& chon &"')"
						Conn.Execute sSQL				
				else
					Msg="Mã luồng đã tồn tại"
					bMsg="ma"
				end if
			case "delete"
					sSQL="Delete from TvWorkFlow Where MaWorkFlow like '"& bMaWorkFlow & "'"
					Conn.Execute sSQL
					sSQL="Delete from TvFlowNode Where MaWorkFlow like '"& bMaWorkFlow & "'"
					Conn.Execute sSQL		
			case "edit"
				if not KTMa(bMa,"edit") then
						on error resume next
						Conn.BeginTrans					
						sSQL="Update TvWorkFlow set MaTvworkFlow='"& ClsFun.ModiString(bma) &"',TenTvWorkFlow='"& ClsFun.ModiString(bTen) &"',Dangky='"& chon &"' Where MaWorkFlow like '" & bMaWorkFlow & "'"
						Conn.Execute sSQL
						if Err.number then
							Conn.RollbackTrans
						else
							Conn.CommitTrans
						end if
						Err.Clear
				else
					Msg="Mã luồng đã tồn tại"
					bMsg="ma"
				end if
		End Select
	End if
	Set Rec=server.CreateObject("ADODB.Recordset") 
	rec.CursorType = 3
	rec.CacheSize=5	
	select case request("bComm")
		case "search"	
			if chon="2" then
				ssql="Select top 400 * from TvWorkFlow where dangky like '2' and TenTvWorkFlow like '%"& ClsFun.ModiString(bsearch) & "%' order by MaTvWorkFlow"
			else
				ssql="Select top 400 * from TvWorkFlow where dangky like '1' and TenTvWorkFlow like '%"& ClsFun.ModiString(bsearch) & "%' order by MaTvWorkFlow"
			end if
		case else
			Loaitim=""
			bsearch=""
			if chon="2" then
				ssql="Select top 400 * from TvWorkFlow where dangky like '2' order by MaTvWorkFlow"
			else
				ssql="Select top 400 * from TvWorkFlow where dangky like '1' order by MaTvWorkFlow"
			end if
	end select
	Dim nRecCount	' Number of records found
	Dim nPageCount	' Number of pages of records we have
	Dim nPage	' Current page number
	nPage=CLng(request("Page"))	
	if nPage="" then nPage=1
	rec.Open ssql,Conn
	if  rec.EOF and rec.BOF then
		nPageCount=0
	end if	
%>

<%if Msg<>"" then%>
  <% if bMsg="ma" then %>
			<center><font size=2 color=red face=Arial>Mã luồng : <%=bma%> &#273;&#227; t&#7891;n t&#7841;i</font></center>
   <%end if%>
   <% if bMsg="" then %>
			<center><font size=2 color=red face=Arial><%=Msg%></font></center>
   <%end if%>
<%end if%>
<!--#include file="..\jvfunction.inc"-->
<script language=VBScript runat=server>
	Function KTMa(bValue,loai)
		KTMa=false
		if loai="add" then
			ssql="Select * from TvWorkFlow  where MaTvWorkFlow like '"& trim(ClsFun.ModiString(bValue)) &"'"
			Set RecTemp=server.CreateObject("ADODB.Recordset") 
			RecTemp.Open ssql,Conn
			if (not rectemp.BOF) and (not RecTemp.EOF) then
				KTMa=True
			end if
			set RecTemp=nothing
		end if
		if loai="edit" then
			if Lcase(bMacu)<>Lcase(bValue) then
				ssql="Select * from TvWorkFlow where MaTvWorkFlow like '"& trim(ClsFun.ModiString(bValue)) &"'"
				Set RecTemp=server.CreateObject("ADODB.Recordset") 
				RecTemp.Open ssql,Conn
				if (not rectemp.BOF) and (not RecTemp.EOF) then
					KTMa=True
				end if
				set RecTemp=nothing
			end if		
		end if
	End function
</script>

<script language=VBScript  runat="server">
</script>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function  SetFocus(){
	if (!nhom.TxtMa.disabled){
		document.nhom.TxtMa.focus()
	}
}
function KTnhap(){
	if (nhom.TxtMa.value==""){
		alert("Bạn cần phải nhập mã");
		nhom.TxtMa.focus();
		return false;
	}
	if (nhom.TxtTen.value==""){
		alert("Bạn cần phải nhập tên");
		nhom.TxtTen.focus();
		return false;
	}
	return true;
}
function CmdAdd_onclick() {
	nhom.TxtMa.value="";
	nhom.TxtTen.value="";
	cmdenable(false);
	Unlockdata();
	nhom.TxtMa.focus();
	nhom.sua.value="2";
}
function cmdenable(bvalue){
	if (bvalue){
		if ("<%= Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)%>"=='1'||"<%= Session("IsAdmin") %>".toLowerCase()=='true'){
			nhom.CmdAdd.disabled= false;
		}			
		else{
			nhom.CmdAdd.disabled= true;		
		}
		nhom.CmdDelete.disabled= false;
		nhom.CmdEdit.disabled= false;
		nhom.CmdLuong.disabled=false;
		nhom.CmdCancel.disabled= true;
		nhom.CmdOK.disabled= true;	
		nhom.CmdSearch.disabled=false;
	}
	else {
		nhom.CmdAdd.disabled= true;
		nhom.CmdDelete.disabled= true;
		nhom.CmdEdit.disabled= true;
		nhom.CmdLuong.disabled=true;
		nhom.CmdCancel.disabled= false;
		nhom.CmdOK.disabled= false;
		nhom.CmdSearch.disabled=true;
	}	
}

function CmdCancel_onclick() {
	cmdenable(true);
	nhom.CmdDelete.disabled= true;
	nhom.CmdEdit.disabled= true;
	nhom.CmdLuong.disabled=true;
	nhom.CmdSearch.value="Tìm kiếm";
	Lockdata();
	nhom.TxtMa.value="";
	nhom.TxtTen.value="";
}

function Lockdata(){
	nhom.TxtMa.disabled=true;
	nhom.TxtTen.disabled=true;
}
function Unlockdata(){
	nhom.TxtMa.disabled=false;
	nhom.TxtTen.disabled=false;
}

function CmdDelete_onclick() {
	if (nhom.TxtMa.value==""){
		alert("Bạn hãy chọn luồng cần xoá");
		return ;
	}
	if(!confirm("Bạn có muốn xoá không ?")){
		return false;	
	}
	ID=nhom.bMaWorkFlow.value;
	b="frmtvworkflow.asp?Page="+"<%=npage%>"+"&bMaWorkFlow="+ID+"&bComm=delete"					
	window.nhom.target="right"
	window.nhom.action=b;
	window.nhom.submit();
}
function CmdEdit_onclick() {
	if (nhom.TxtMa.value==""){
		alert("Bạn hãy chọn luồng cần xoá");
		return ;
	}
	cmdenable(false);
	Unlockdata();
	nhom.TxtMa.focus();
	<%bTempComm="edit"%>
	nhom.sua.value="1";
	nhom.Macu.value=nhom.TxtMa.value;
	nhom.Tencu.value=nhom.TxtTen.value;
}
function CmdOK_onclick() {
	if (KTnhap()){
		cmdenable(true);
		Lockdata();
		ma=nhom.TxtMa.value;
		ten=nhom.TxtTen.value;
		macu=nhom.Macu.value;
		tencu=nhom.Tencu.value;
		bc=nhom.sua.value;
		cp=nhom.cPage.value;
		if (nhom.R1.checked)
		{	
			bchon="1";
		}
		else
		{
			bchon="2";
		}
		if (bc=="1"){
			b="frmtvworkflow.asp?Page="+cp+"&bMacu="+macu+"&bTencu="+tencu+"&bma="+ma+"&bTen="+ten+"&bComm=edit&chon="+bchon;		
		}
		
		else {
			b="frmtvworkflow.asp?Page="+cp+"&bma="+ma+"&bTen="+ten+"&bComm=add&chon="+bchon;
		}
			window.nhom.target="right"
			window.nhom.action=b;
			window.nhom.submit();
	}
}

function CmdSearch_onclick() {
	nhom.CmdAdd.disabled=true;
	nhom.CmdCancel.disabled=false;
	nhom.CmdEdit.disabled=true;
	nhom.CmdLuong.disabled=true;
	nhom.CmdDelete.disabled=true;
	if (nhom.TxtTen.disabled){
		nhom.CmdSearch.value="Tìm";
		Unlockdata()
		nhom.TxtMa.value="";
		nhom.TxtTen.value="";
		Lockdata()
		nhom.TxtTen.disabled=false;
		nhom.TxtTen.value="";
		nhom.TxtTen.focus();
		return false;
	}
	value=nhom.TxtTen.value;
	blink="frmTvWorkFlow.asp?Chon="+"<%=request("Chon")%>"+"&bsearch="+value+"&bComm=search";
	window.nhom.action=blink;
	window.nhom.target="right"
	window.nhom.submit();	
}
function CmdLuong_onclick()
{
	Idflow=nhom.bMaWorkFlow.value;
	if (nhom.R1.checked)
	{
	window.nhom.target="right"
	window.nhom.action="frmtvflownode.asp?Idflow="+Idflow;
	window.nhom.submit();
	}
	if (nhom.R2.checked)
	{
	window.nhom.target="right"
	window.nhom.action="frmtvflownodecd.asp?Idflow="+Idflow;
	window.nhom.submit();
	}
}

function Cmdcotontai_onclick()
{
	window.nhom.target="right"
	window.nhom.action="frmtvworkflow.asp?chon=1";
	window.nhom.submit();
}


function Cmdkhongontai_onclick()
{
	window.nhom.target="right"
	window.nhom.action="frmtvworkflow.asp?chon=2";
	window.nhom.submit();
}
//-->
</SCRIPT>
<body  topmargin="0" leftmargin="0" bgcolor=#F8F9D9 style="Font-Family: Times New Roman" onload="SetFocus()">
<form name="nhom" method="POST">
	<input type="hidden" name="sua" value="">
	<input type="hidden" name="Macu" value="">
	<input type="hidden" name="Tencu" value="">
	<input type="hidden" name="bMaWorkFlow" value="<%=bMaWorkFlow%>">
	<input type="hidden" name="cPage" value="<%=nPage%>">
	<center><b>CẬP NHẬT THƯ VIỆN LUỒNG XỬ LÝ</b></center>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-family:arial;BORDER-BOTTOM-STYLE: none; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0"  bgcolor="#BDD5D0" bordercolor="#111111">
  <tr>
  <% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)="1" or Session("IsAdmin") then	%>
		<td width="14%"><input type="button" value="Thêm" name="CmdAdd" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdAdd_onclick()"></td>
		<%if  bcomm<>"detail" then%>
			<td width="14%"><input type="button" value="Xóa" disabled name="CmdDelete" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdDelete_onclick()"></td>
			<td width="14%"><input type="button" value="Sửa" disabled name="CmdEdit" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdEdit_onclick()" ></td>
			<td width="14%"><input type="button" value="Luồng" disabled name="CmdLuong" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdLuong_onclick()" ></td>

		<%else%>  
			<td width="14%"><input type="button" value="Xóa" name="CmdDelete" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdDelete_onclick()"></td>
			<td width="14%"><input type="button" value="Sửa" name="CmdEdit" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdEdit_onclick()" ></td>
			<td width="14%"><input type="button" value="Luồng" name="CmdLuong" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdLuong_onclick()"></td>
		<%end if%>
		<td width="14%"><input type="button" disabled value="Ghi nhận" name="CmdOK" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdOK_onclick()"></td>
		<td width="14%"><input type="button" disabled value="B&#7887; qua" name="CmdCancel" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdCancel_onclick()"></td>
		<td width="14%"><input type="button" value="Tìm kiếm" name="CmdSearch" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdSearch_onclick()"></td>
	<%else%>
		<td width="14%"><input type="button" value="Thêm" disabled  name="CmdAdd" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdAdd_onclick()"></td>
		<td width="14%"><input type="button" value="Xóa" disabled name="CmdDelete" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdDelete_onclick()"></td>
		<td width="14%"><input type="button" value="Sửa" disabled name="CmdEdit" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdEdit_onclick()" ></td>
		<td width="14%"><input type="button" value="Luồng" disabled name="CmdLuong" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdLuong_onclick()" ></td>
		<td width="14%"><input type="button" value="Ghi nhận" disabled  name="CmdOK" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdOK_onclick()"></td>
		<td width="14%"><input type="button" value="B&#7887; qua" disabled  name="CmdCancel" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdCancel_onclick()"></td>
		<td width="14%"><input type="button" value="Tìm kiếm" name="CmdSearch" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdSearch_onclick()"></td>
    <%end if%>
  </tr>
</table>

<table width="100%" border="0" cellspacing="0" style="font-size:12pt;BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: none;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0" bordercolor="#111111" bgcolor="#BDD5D0">
  <% if bcomm="detail" then %>
	  <tr>
		<td width="10%" nowrap>Mã luồng</td>
		<td width="20%"><input type="text" name="TxtMa" disabled=true value="<%=bma%>" size="15" maxLength=50 style="FONT-FAMILY: Arial;width:100%"></td>
		<td width="15%" align="center">Tên luồng</td>
		<td width="55%" colspan=2><input type="text" name="TxtTen" disabled=true value="<%=bten%>" size="50" maxLength=100 style="FONT-FAMILY: Arial;width:100%"></td>
	  </tr>
	<%else%>
		<tr>
		<td width="10%" nowrap>Mã luồng</td>
		<td width="20%"><input type="text" name="TxtMa" disabled=true size="15" maxLength=50 style="FONT-FAMILY: Arial;width:100%"></td>
		<td width="15%" align="center">Tên luồng</td>
		<td  width="55%" colspan=2><input type="text" name="TxtTen" disabled=true size="50" maxLength=100 style="FONT-FAMILY: Arial;width:100%"></td>
	  </tr>
	<%end if%>
</table>
<Div align=center>
	<%if chon="2" then%>
		<input type="radio" ID=R1 value=1  name =cotontai LANGUAGE=javascript onclick="return Cmdcotontai_onclick()"><label for=R1>Luồng xử lý mẫu</label>
		<input type="radio" ID=R2 value=2 checked name=khongtontai LANGUAGE=javascript onclick="return Cmdkhongontai_onclick()"><label for=R2>Thư viện mẫu</label>
	<%else%>
		<input type="radio" ID=R1 value=1 checked name =cotontai LANGUAGE=javascript onclick="return Cmdcotontai_onclick()"><label for=R1>Luồng xử lý mẫu</label>
		<input type="radio" ID=R2 value=2  name=khongtontai LANGUAGE=javascript onclick="return Cmdkhongontai_onclick()"><label for=R2>Thư viện mẫu</label>
	<%end if%>
</Div>
<table border="0" style="BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;Border-color:#C0C0C0" WIDTH="100%" cellspacing=1 cellpadding=0>
  <tr>
    <td width="100%" colspan="3" bgcolor="#173584">
    <p align="center"><b><font color="#FFFFFF" size="2">DANH MỤC LUỒNG XỬ LÝ</font></b></td>
  </tr>
  <tr bgcolor="#BDD5D0">
    <td width="20%" align="center"><b>Mã luồng</b></td>
    <td width="80%" align="center"><b>Tên luồng</b></td>
  </tr>
  <%	
	If Not Rec.Eof Then
		nRecCount = Rec.RecordCount
		Rec.PageSize = 20
		nPageCount = Rec.PageCount
		If nPage < 1 then
			nPage = 1			
		End If
		if nPage > nPageCount Then
			nPage=nPageCount
		end if
		cnt=(pg-1)*pgsize + 1		    
		STT=1
		rec.AbsolutePage=nPage
		howmanyrecs=0
		do while not Rec.EOF and howmanyrecs<rec.PageSize
			if (cnt/2=int(cnt/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if
%>
			<tr id=mnu_<%=STT%> style="BORDER-RIGHT: #e7e7e7 1px solid; BORDER-TOP: #e7e7e7 1px solid; BORDER-LEFT: #e7e7e7 1px solid; COLOR: #666666; BORDER-BOTTOM: #e7e7e7 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: <%=color%>" onmouseover="javascript:MouseOverMenu('mnu_<%=STT%>')" onmouseout="javascript:MouseOutMenu('mnu_<%=STT%>','<%=color%>')">
			  <td width="20%" align=center height="1"><a onmouseout="window.status='';return true" onmouseover="window.status='Ch&#7885;n th&#244;ng tin';return true" style='text-decoration: none' href="frmTvWorkFlow.asp?chon=<%=chon%>&page=<%=nPage%>&bMaWorkFlow=<%=Rec("MaWorkFlow")%>&bma=<%=Rec("MaTvWorkFlow")%>&bComm=<%="detail"%>"><%=Rec("MaTvWorkFlow")%></a></td>
			  <td width="80%" height="1"><a onmouseout="window.status='';return true" onmouseover="window.status='Ch&#7885;n th&#244;ng tin';return true" style='text-decoration: none' href="frmTvWorkFlow.asp?chon=<%=chon%>&page=<%=nPage%>&bMaWorkFlow=<%=Rec("MaWorkFlow")%>&bma=<%=Rec("MaTvWorkFlow")%>&bComm=<%="detail"%>"><%=Rec("TenTvWorkFlow")%></a></td>
			</tr>
<%			STT=STT+1
			Rec.MoveNext
			cnt=cnt+1
			howmanyrecs=howmanyrecs+1
		loop
	end if
	rec.Close
	set rec=nothing
	
%>  
</table>
 </form>
  <%
response.write "<Table width='100%'>"
response.write "<TR>"
response.write "<TD width='15%'>"
response.write "<p align=left>Trang:  " & cstr(nPage) & "/" & cstr(nPageCount)
response.write "</TD>"
response.write "<TD>"

Response.Write "<font face=Arial>" 
response.write "<p align=center>"
for counter=1 to nPageCount
	if bComm<>"search"  then
		txt="&nbsp;<a href='frmTvWorkFlow.asp?bsearch="& bsearch &"&Loaitim="& loaitim &"&page="+ cstr(counter)+ "&bComm='>" & counter & "</a>&nbsp;"
	else
		txt="&nbsp;<a href='frmTvWorkFlow.asp?bsearch="& bsearch &"&Loaitim="& loaitim &"&page="+ cstr(counter)+ "&bComm=search'>" & counter & "</a>&nbsp;"
	end if
	response.write(txt)
next
Response.Write "</font>" 
response.write "</TD>"
response.write "</TR>"
response.write "</Table>"
%>
</body>

</html>


<%
	Conn.Close
	Set Conn=nothing
	set ClsFun=nothing
%>